﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;

    public class GameMapMakerSceneUI
    {

       
         
        int SelectBlockIndex = -1;
        Dictionary<int, Texture> BlockTextures = new Dictionary<int,Texture>();
        public void OnSceneGUI()
        {
            if(this.BlockTextures.Count !=MapBlockData.Inst.Blocks.Count) 
            {
              foreach(KeyValuePair<int,MapStaticBlock> block in MapBlockData.Inst.Blocks)
              {
                 this.BlockTextures.Add(block.Key, (Texture)Resources.Load("BlockThumb/"+block.Key.ToString()));
              }
            }
            GameMapEditorPanel.Inst.Draw();
            this.DrawTileGrid();
        }


       

        void DrawTileGrid()
        {
            Handles.BeginGUI();
            EditorGUI.DrawRect(new Rect(0, 0, Screen.width, 80), Color.gray);
            Vector3 Origin = new Vector3(10 + 80,0);
            
            if (GUI.Button(new Rect(10, Origin.y, 75, 75),"擦除"))
            {
                this.SelectBlockIndex = -1;
                GameMapEditorPanel.Inst.OnSelectBlock(this.SelectBlockIndex);
            }
            int i = 0;
            foreach (KeyValuePair<int,MapStaticBlock> data in MapBlockData.Inst.Blocks)
            {
                if (this.SelectBlockIndex == i) 
                {
                    GUI.backgroundColor = Color.black;
                }
                else
                {
                    GUI.backgroundColor = new Color(0, 0, 0, 0);
                }
                GUI.Box(new Rect(Origin.x + i * 80, Origin.y, 75, 80), "");
                GUI.backgroundColor = new Color(0,0,0,0);
                if (GUI.Button(new Rect(Origin.x + i * 80, Origin.y, 75, 75), this.BlockTextures[data.Key]))
                {
                    this.SelectBlockIndex = i;
                    GameMapEditorPanel.Inst.OnSelectBlock(data.Key);
                }
                i++;
            }
            Handles.EndGUI();
        }   
    }